package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.to.SkuReductionTo;
import com.ruoyi.common.core.to.SpuBoundTo;
import com.ruoyi.system.api.RemoteCouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @program: zqs-mall
 * @description: 优惠卷服务降级处理
 * @author: Mr.Zhang
 * @create: 2022-06-21 23:27
 **/
@Component
public class RemoteCouponFallbackFactory implements FallbackFactory<RemoteCouponService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteCouponFallbackFactory.class);

    @Override
    public RemoteCouponService create(Throwable throwable) {
        log.error("优惠卷服务调用失败:{}", throwable.getMessage());
        return new RemoteCouponService() {
            @Override
            public R saveSpuBounds(SpuBoundTo spuBoundTo) {
                return R.fail("保存spu失败" + throwable.getMessage());
            }

            @Override
            public R saveSkuReduction(SkuReductionTo skuReductionTo) {
                return R.fail("保存sku失败" + throwable.getMessage());
            }
        };
    }
}
